package com.ruoyi.question.service.impl;

import com.ruoyi.question.domain.DtQuestion;
import com.ruoyi.question.domain.DtWrongQuestion;
import com.ruoyi.question.mapper.DtWrongQuestionMapper;
import com.ruoyi.question.service.IDtWrongQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 错题管理Service业务层处理
 *
 * @author llc
 * @date 2025-01-07
 */
@Service
public class DtWrongQuestionServiceImpl implements IDtWrongQuestionService {
    @Autowired
    private DtWrongQuestionMapper dtWrongQuestionMapper;
    @Autowired
    private DtQuestionServiceImpl dtQuestionService;

    /**
     * 查询错题管理
     *
     * @param id 错题管理主键
     * @return 错题管理
     */
    @Override
    public DtWrongQuestion selectDtWrongQuestionById(Long id) {
        DtWrongQuestion dtWrongQuestion = dtWrongQuestionMapper.selectDtWrongQuestionById(id);
        dtWrongQuestion.setDtQuestion(dtQuestionService.selectDtQuestionById(dtWrongQuestion.getQuestionId()));
        return dtWrongQuestion;
    }

    /**
     * 查询错题管理列表
     *
     * @param dtWrongQuestion 错题管理
     * @return 错题管理
     */
    @Override
    public List<DtWrongQuestion> selectDtWrongQuestionList(DtWrongQuestion dtWrongQuestion) {
        List<DtWrongQuestion> list = dtWrongQuestionMapper.selectDtWrongQuestionList(dtWrongQuestion);
        for (DtWrongQuestion wrongQuestion : list) {
            Long questionId = wrongQuestion.getQuestionId();
            if (questionId != null) {
                DtQuestion dtQuestion = dtQuestionService.selectDtQuestionById(questionId);
                wrongQuestion.setDtQuestion(dtQuestion);
            }
        }
        return list;
    }


    /**
     * 新增错题管理
     *
     * @param dtWrongQuestion 错题管理
     * @return 结果
     */
    @Override
    public int insertDtWrongQuestion(DtWrongQuestion dtWrongQuestion) {

        return dtWrongQuestionMapper.insertDtWrongQuestion(dtWrongQuestion);
    }

    /**
     * 修改错题管理
     *
     * @param dtWrongQuestion 错题管理
     * @return 结果
     */
    @Override
    public int updateDtWrongQuestion(DtWrongQuestion dtWrongQuestion) {
        return dtWrongQuestionMapper.updateDtWrongQuestion(dtWrongQuestion);
    }

    /**
     * 批量删除错题管理
     *
     * @param ids 需要删除的错题管理主键
     * @return 结果
     */
    @Override
    public int deleteDtWrongQuestionByIds(Long[] ids) {
        return dtWrongQuestionMapper.deleteDtWrongQuestionByIds(ids);
    }

    /**
     * 删除错题管理信息
     *
     * @param id 错题管理主键
     * @return 结果
     */
    @Override
    public int deleteDtWrongQuestionById(Long id) {
        return dtWrongQuestionMapper.deleteDtWrongQuestionById(id);
    }
}
